@extends('admin.formLayout')
@if(isset($id))
    @section('title','编辑菜单')
@section('barName','编辑菜单')
@else
    @section('title','添加菜单')
@section('barName','添加菜单')
@endif
@section('content')
    <form class="layui-form" @if(!isset($id)) action="{{route('admin.dev-menu-add')}}" @else action="{{route('admin.dev-menu-edit',['id'=>$id])}}" @endif method="post">
        <div class="layui-tab" lay-filter="posts">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                        <div class="layui-col-md8">
                            {{csrf_field()}}
                            @if(isset($id))
                                <input type="hidden" name="id" value="{{$id}}">
                            @endif
                            <div class="layui-form-item">
                                <label class="layui-form-label">菜单名称<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="title" lay-verify="required"  value="@if(old('title')){{old('title')}}@else{{$model->title or ''}}@endif" autocomplete="off" placeholder="请输入标题" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">排序</label>
                                <div class="layui-input-block">
                                    <input type="number" name="order" value="@if(old('order')){{old('order')}}@else{{$model->order or ''}}@endif"  class="layui-input" placeholder="请填写整数,值越小文菜单靠前。">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">路径</label>
                                <div class="layui-input-block">
                                    <input type="text" name="href"   value="@if(old('href')){{old('href')}}@else{{$model->href or ''}}@endif" autocomplete="off" placeholder="eg:/admin/index" class="layui-input" >
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">权限<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <select lay-verify="required" name="permission">
                                        @foreach($permission as $k=>$v)
                                            <option value="{{$v['name']}}" @if(old('permission')){{(old('permission')==$v['name'])?'selected':''}}@else{{ (isset($model->permission)&&$model->permission==$v['name']) ?'selected':''}} @endif>{{$v['name']}} ------ {{$v['desc']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">上级菜单<span style="color:red">*</span></label>
                                <div class="layui-input-block">
                                    <select lay-verify="required" name="parent_id">
                                        <option value="0">顶级菜单</option>
                                        @foreach($topAry as $k=>$v)
                                            @if(isset($model->id))
                                                @if($v['id']!=$model->id)
                                                    <option value="{{$v['id']}}" @if(old('parent_id')){{(old('parent_id')==$v['id'])?'selected':''}}@else{{ (isset($model->parent_id)&&$model->parent_id==$v['id']) ?'selected':''}} @endif>{{$v['title']}}</option>
                                                @endif
                                            @else
                                                <option value="{{$v['id']}}" @if(old('parent_id')){{(old('parent_id')==$v['id'])?'selected':''}}@endif>{{$v['title']}}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">图标</label>
                                <div class="layui-input-block">
                                    <input name="icon" type="text" value="@if(old('icon')){{old('icon')}}@else{{$model->icon or ''}}@endif" placeholder="请输入图标样式" autocomplete="off" class="layui-input"/>
                                </div>
                                <div class="layui-input-block">
                                    <p style="margin-top:10px ">
                                        详细图标请访问<a href="https://www.thinkcmf.com/font/font_awesome/icons.html" style="color:#3b97d7" target="_blank">奥森图库</a>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                <button type="button"  onclick="javascript:location.href='{{route('admin.dev-menu')}}'" class="layui-btn layui-btn-primary">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
@endsection
@section('script')

    <script>
        layui.use(['element','form','layer','upload'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var upload = layui.upload;
            form.on('submit(*)',function(data){
                console.log(data);
                return false;
            });
            //一些事件监听
            element.on('tab(posts)', function(data){
            });
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    layer.msg('{{$error}}',{'icon':2});
            @break
            @endforeach
            @endif

        });
    </script>
@endsection